function sum(...args) {
    let _args = args
    return function () {
        if (arguments.length === 0) { // 最后一次调用
            return _args.reduce((pre, item) => {
                return pre + item
            }, 0)
        } else {
            _args = [...args, ...arguments]
            return sum(..._args)
        }
    }
}

sum(1, 2)()
sum(1, 2, 3)(4, 5)()
console.log(sum(1, 2, 3)(4, 5)());
